package com.bbx.demo.protobuf;

import com.bbx.protobuf.DataInfo;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.extern.slf4j.Slf4j;

/**
 * 测试序列化与烦序列化
 */
@Slf4j
public class ProtobufTest {


    public static void main(String [] args) throws InvalidProtocolBufferException {
        DataInfo.Student student = DataInfo.Student.newBuilder()
                .setName("bbx")
                .setAge(21)
                .setAddress("山西省")
                .build();

        //序列化
        byte[] studentBytes = student.toByteArray();
        //反序列化
        DataInfo.Student student1 = DataInfo.Student.parseFrom(studentBytes);
        log.info("name[{}]", student1.getName());
        log.info("age[{}]", student1.getAge());
        log.info("address[{}]", student1.getAddress());

    }




}
